import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2023-11-10
 * Time:14:18
 * Text：
 */
public class text4 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int start=sc.nextInt();
        int day=sc.nextInt();
        int count=day%7;
        if(7-start>count){
            System.out.println(start+count);
        }else{
            System.out.println(count-(7-start));
        }
    }
}
